<template>
  <div>
    <el-form label-width="100px" size="mini" class="form-view">
      <el-row>
        <el-col :span="24">
          <el-form-item label="分配明细">
            <el-table
              :loading="false"
              :data="formItem.lingyong"
              border
              class="fixed-table-table"
              size="mini"
              max-height="240px"
            >
              <el-table-column
                label="序号"
                type="index"
                width="50"
                header-align="center"
                align="center"
              />
              <el-table-column v-for="column in insideColumns2" :key="column.key" header-align="center" align="center" :label="column.title" :prop="column.key" :sortable="column.sortable">
                <template slot-scope="scope">
                  <column-render :render="column.render" :row="scope.row" :column="column" />
                </template>
              </el-table-column>
              <el-table-column v-if="formItem.categories === '3'" header-align="center" align="center" label="配发数量">
                <template slot-scope="scope">
                  <span>{{ scope.row.lingyongQuantity }}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <ViewDialog
      :append-to-body="true"
      class="fixed-dialog-height"
      title="资产信息"
      :show.sync="dialogViewVisible"
      width="70%"
      @on-cancel="viewCancel"
    >
      <ViewForm v-if="dialogViewVisible" :code="code" :view-type="viewType" />
    </ViewDialog>
  </div>
</template>
<script>
import { confirmDetail as detail } from '@neu/dcam-ui/api/lingyongSL'
// import PageableTable from '@neu/biz-core/components/PageableTable'

import ViewForm from '../../../fixedAsset/components/viewForm/viewForm'
import ViewDialog from '@neu/biz-core/components/ViewDialog'
export default {
  components: {
    // PageableTable
    ViewDialog,
    ViewForm
  },
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      formItem: {},
      dialogViewVisible: false,
      code: -1,
      viewType: 1,
      insideColumns2: [
        { title: '资产名称', width: 100, key: 'name',
          render: (h, params) => { // 查看功能
            if (!this.forSelection) {
              return h('span', [
                h('el-link', {
                  class: 'font-12',
                  attrs: { title: params.row.name },
                  props: { type: 'primary' },
                  on: { click: () => { this.view(params.row) } }},
                params.row.name)
              ])
            } else {
              return h('span', params.row.name)
            }
          }
        },
        { title: '资产编号', width: 120, key: 'code' },
        { title: '资产分类', width: 300, key: 'type',
          render: (h, params) => {
            let txt = params.row.smallTypeName
            if (params.row.middleTypeName) {
              txt = params.row.middleTypeName + ' / ' + txt
            }
            if (params.row.bigTypeName) {
              txt = params.row.bigTypeName + ' / ' + txt
            }
            return h('span', txt)
          }
        },
        { title: '规格型号', width: 100, key: 'specifications' },
        { title: '品牌', width: 100, key: 'brand' },
        { title: '金额', width: 100, key: 'money' },
        { title: '用途', key: 'purpose' }
        // { title: '序列号', width: 100, key: 'serialnumber' }
      ],
      rules: {}
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = { ...response.data }
          if (this.formItem.categories === '3') {
            const hiddenColumns = ['bigTypeName', 'middleTypeName', 'originalCode', 'supplierName', 'locationName', 'code', 'card', 'serialnumber', 'computerRoom', 'cabinet', 'location', 'maintenanceStartTime', 'maintenanceEndTime', 'contractNo', 'usePeriod', 'managementOrgName', 'managementUserName']
            this.insideColumns2 = this.insideColumns2.filter(e => !hiddenColumns.includes(e.key))
          }
        })
      }
    },
    view(row) {
      debugger
      // 打开对话框
      this.code = row.code
      this.instance = row
      this.dialogViewVisible = true
    },
    viewCancel() {
      this.code = -1
      // 关闭对话框
      this.dialogViewVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
  .fixed-table-table {
    margin: 8px 8px 8px 0;
  }
</style>
